﻿-- Creating table 'Products'
CREATE TABLE [dbo].[Products] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(50)  NOT NULL,
    [CategoryId] int  NOT NULL,
    [ProductUnitId] int  NOT NULL,
    [ProductPricingPerUnitId] int  NOT NULL,
    [CreateOn] datetime  NOT NULL,
    [DeleteOn] datetime  NULL
);
GO
-- Creating foreign key on [CategoryId] in table 'Products'
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [FK_CategoryProduct]
    FOREIGN KEY ([CategoryId])
    REFERENCES [dbo].[Categories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- Creating foreign key on [ProductUnitId] in table 'Products'
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [FK_ProductUnitProduct]
    FOREIGN KEY ([ProductUnitId])
    REFERENCES [dbo].[ProductUnits]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- Creating foreign key on [ProductPricingPerUnitId] in table 'Products'
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [FK_ProductPricingPerUnitProduct]
    FOREIGN KEY ([ProductPricingPerUnitId])
    REFERENCES [dbo].[ProductPricingPerUnits]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO
-- Creating primary key on [Id] in table 'Products'
ALTER TABLE [dbo].[Products]
ADD CONSTRAINT [PK_Products]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryProduct'
CREATE INDEX [IX_FK_CategoryProduct]
ON [dbo].[Products]
    ([CategoryId]);
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_ProductUnitProduct'
CREATE INDEX [IX_FK_ProductUnitProduct]
ON [dbo].[Products]
    ([ProductUnitId]);
GO
-- Creating non-clustered index for FOREIGN KEY 'FK_ProductPricingPerUnitProduct'
CREATE INDEX [IX_FK_ProductPricingPerUnitProduct]
ON [dbo].[Products]
    ([ProductPricingPerUnitId]);